package com.nd.android.u.ui.activity.addGroupMember.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.common.utils.StarAppUtils;
import com.nd.android.u.ui.R;


/**
 * 选择用户下拉框适配器
 * <br>Created 2014-5-15 下午2:45:56
 * @version  
 * @author   linsj		
 *
 * @see 	 
 */
public class AddFriendOrGroupAdapter extends BaseAdapter {
	
	/**目前列表项有两个：发起群聊和添加朋友*/
	private final int ITEM_COUNT = 2;
	
	/**发起群聊*/
	public static final int ACTION_CREATE_GROUP = 0;
	
	/**添加朋友*/
	public static final int ACTION_ADD_FRIENDS = 1;
	
    /**上下文*/
    private Context mContext;
    
    /**
     * 构造方法
     * Creates a new instance of SelectUserAdapter.
     * <br>Created 2014-5-15 下午2:47:22
     * @param context	上下文
     */
    public AddFriendOrGroupAdapter(Context context) {
        super();
        mContext = context;
    }

    @Override
    public int getCount() {
        return ITEM_COUNT;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.add_friend_or_group, null);
            holder = new Holder();
            holder.ivIcon = (ImageView)convertView.findViewById(R.id.iv_icon);
            holder.tvAction = (TextView)convertView.findViewById(R.id.tv_account);
            StarAppUtils.setViewTypeFace(holder.tvAction, false);
            convertView.setTag(holder);
        } else{
            holder = (Holder)convertView.getTag();
        }

        initData(holder, position);
        return convertView;
    }
    
    /**
     * 初始化数据
     * 
     * <br>Created 2014-6-12 下午4:41:20
     * @param holder	view保持类
     * @param iPos		索引
     * @author        :  linsj
     */
    private void initData(Holder holder, int iPos){
    	if(null == holder){
    		return;
    	}
    	
    	switch (iPos) {
		case 0:
			holder.ivIcon.setBackgroundResource(R.drawable.chat_create_group_icon);
			holder.tvAction.setText(R.string.chat_create_group);
			break;
		case 1:
			holder.ivIcon.setBackgroundResource(R.drawable.chat_add_friend_icon);
			holder.tvAction.setText(R.string.chat_add_friends);
			break;
		default:
			break;
		}
    }

    /**
     * item项数据存储
     * <br>Created 2014-5-15 下午2:49:05
     * @version  SelectUserAdapter
     * @author   linsj		
     *
     * @see 	 
     */
    private class Holder {
    	ImageView ivIcon;
        TextView tvAction;
    }
}
